package com.itetchologyandenglish.home.controller.Page;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itetchologyandenglish.home.enetity.Auth;
import com.itetchologyandenglish.home.enetity.AuthUser;
import com.itetchologyandenglish.home.enetity.Result;
import com.itetchologyandenglish.home.service.AuthService;
import com.itetchologyandenglish.home.service.UserAthService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Controller
public class AuthUserPageController {
    @Resource
    UserAthService userAthService;
    @Resource
    AuthService authService;
    @RequestMapping("/login")
    public ModelAndView login(){
        return new ModelAndView("login");
    }
    @RequestMapping("/admin/index")
    public ModelAndView index(){
        return new ModelAndView("index");
    }
    @ResponseBody
    @RequestMapping(value = "/getSession",produces = "application/json")
    public Result getSession(HttpSession session){
        AuthUser user=(AuthUser)session.getAttribute("user");
        if(user==null){
            session.setAttribute("user",null);
        }
        return new Result<AuthUser>(200,"success",user);
    }
    @RequestMapping("/updatepwd")
    public ModelAndView updatepwd(HttpSession session){
        return new ModelAndView("updatepwd");
    }
    @RequestMapping("/page/log")
    public ModelAndView log(ModelAndView model){
        List<Auth> authList=authService.list();
        model.getModel().put("authList",authList);
        model.setViewName("log");
        return model;
    }

}
